package com.mall.service.homepage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.commons.common.CommonPage;
import com.mall.model.domain.CmsSubject;
import com.mall.service.homepage.mapper.SubjectMapper;
import com.mall.service.homepage.service.SubjectService;
import org.springframework.stereotype.Service;

/**
 * @Author Pan Rundong
 * @Date 2023-03-13 14:25
 * @Desc 商品专题Service实现类
 */
@Service
public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, CmsSubject> implements SubjectService {
    /**
     * 分页获取商品专题
     *
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return com.mall.commons.common.CommonPage<com.mall.model.domain.CmsSubject>
     * @Author Pan Rundong
     */
    @Override
    public CommonPage<CmsSubject> getPage(Integer pageNum, Integer pageSize, String keyword) {
        // 1.新建分页对象，放入条件
        Page<CmsSubject> page = new Page<>(pageNum, pageSize);

        // 2.设置查询条件，进行模糊查询
        LambdaQueryWrapper<CmsSubject> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(keyword != null, CmsSubject::getTitle, keyword);
        this.page(page, queryWrapper);

        // 3.封装对象
        CommonPage<CmsSubject> commonPage = CommonPage.getPage(page);
        return commonPage;
    }
}
